import Login from '@/views/Login/index.vue'
import Layout from '@/views/Layout/index.vue'
// 二级路由
import Home from '@/views/Home/index.vue'
import Category from '@/views/Category/index.vue'
import SubCategory from '@/views/SubCategory/index.vue'
import Detail from '@/views/Detail/index.vue'
import CartList from '@/views/CartList/index.vue'
import Checkout from '@/views/Checkout/index.vue'
import Pay from '@/views/Pay/index.vue'
import PayBack from '@/views/Pay/PayBack.vue'
// 个人中心的二级路由
import Member from '@/views/Member/index.vue'
// 个人中心的三级路由 用户信息页面
import UserInfo from '@/views/Member/components/UserInfo.vue'
// 个人中心的三级路由 用户订单页面
import UserOrder from '@/views/Member/components/UserOrder.vue'
import { createRouter, createWebHistory } from 'vue-router'
// createRouter:创建router实例对象
// createWebHistory:创建history模式的路由
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    // 首页
    {
      path: '/',
      component: Layout,
      // 二级路由 记得在一级路由中配置二级路由的出口
      children: [
        {
          // 将二级路由的home页置空 称为默认二级路由
          path: '',
          component: Home
        },
        // 分类页面
        {
          path: 'category/:id',
          component: Category
        },
        {
          path: 'category/sub/:id',
          component: SubCategory
        },
        // 详情页
        {
          path: 'detail/:id',
          component: Detail
        },
        // 购物车列表
        {
          path: 'cartList',
          component: CartList
        },
        // 订单页
        {
          path: 'checkout',
          component: Checkout
        },
        // 支付页
        {
          path: 'pay',
          component: Pay
        },
        {
          path: 'paycallback',
          component: PayBack
        },
        // 个人中心 二级路由
        {
          path: 'member',
          component: Member,
          // 三级路由
          children: [
            {
              path: '',
              component: UserInfo
            },
            {
              path: 'order',
              component: UserOrder
            }
          ]
        }
      ]
    },
    // 登录
    {
      path: '/login',
      component: Login
    },

  ],
  // 路由跳转时，页面滚动到顶部
  scrollBehavior() {
    return { top: 0 }
  }
})

export default router
